﻿using MediatR;
using ProductIntory.Domains;
using ProductIntory.ErrorCodes;
using ProductIntory.Infrastructures.Interface;
using ProductIntory.Read.Apis.Application.Command.ProductStatesCommands;

namespace ProductIntory.Read.Apis.Application.CommandHandler.ProductStatesCommandHandlers
{
    public class ShowProductStatesCommandHandlers : IRequestHandler<ShowProductStatesCommand, ApiResult<List<ProductStates>>>
    {
        IBaseRepository<ProductStates> ProductStates;

        public ShowProductStatesCommandHandlers(IBaseRepository<ProductStates> ProductStates)
        {
            this.ProductStates = ProductStates;
        }

        public async Task<ApiResult<List<ProductStates>>> Handle(ShowProductStatesCommand request, CancellationToken cancellationToken)
        {
            var list = ProductStates.GetAll().ToList();
            return new ApiResult<List<ProductStates>>
            {
               Code=ApiEnum.success,
               Message="Get all product states successfully",
               Data=list
            }; 
        }
    }
}
